<template>
  <div id="Company">
    <el-dialog width="900px" :visible.sync="show">
      <vj-table  :page-obj="pageObj" @loadTable="onSearch" :loading="loading" :cfg-list="cfgList"
                :table-data="tableData"/>
    </el-dialog>
  </div>
</template>
<script lang="ts">
import Vue, {ComponentOptions, VueConstructor} from "vue"
import Component from 'vue-class-component'
import BodyContainer from "@/components/layout/body-container.vue";
import SearchFormContainer from "@/components/layout/search-form-conatiner.vue";
import {Mixins, Ref} from "vue-property-decorator";
import {TableMixin} from "@/plugins/mixins/table";
import {requestByGet, requestByPost} from "@/utils/request";
import {formatOptions, groupBy, hookLoading, itemFromArr, updateCfgOption} from "vijay-util";
import TextButton from "@/components/basic/text-button.vue";
import {CompanyDeliveryTB, CompanyJobTB, CompanyTB, PuzzleRecordTB, UserTB} from "@/config/table";
import UserDialog from "@/components/dialog/user-dialog.vue";
import {CompanySH, PictureSH, UserSH} from "@/config/search";
import {warnConfirm} from "@/utils/logic";
import CompanyDialog from "@/components/dialog/company/company-dialog.vue";
import CompanyAddDialog from "@/components/dialog/company/company-add-dialog.vue";
import CompanyTableDialog from "@/components/dialog/company/company-table-dialog.vue";

export const title = "user";
@Component({
  components: {
    CompanyTableDialog,
    CompanyAddDialog, CompanyDialog, UserDialog, TextButton, SearchFormContainer, BodyContainer
  }
})
export default class Company extends Mixins(TableMixin) implements ComponentOptions<Vue> {
  name = "Company"
  show = false
  private businessid: any;
  private type: any = null;

  @hookLoading()
  async onSearch(pageNo?, pageSize?) {
    const params = Object.assign({pageNo, pageSize, name: this.keyWords,businessid:this.businessid}, this.searchForm);
    const res = await requestByGet(`qqc/${this.type?'qqcApplyposts':'qqcPosts'}/list`, params);
    this.tableData = res.records;
    return res;
  }
  async initOptions(){
    const {records} = await requestByGet(`qqc/qqcPoststype/list`,{pageNo:1,pageSize:999});
    const col= itemFromArr(this.cfgList,"propName","typeid");
    if (!col)return;
    col.formatter = function ({typeid}) {
      const target = records.find(({id})=>+id===+typeid);
      return target&&target.name
    }
  }
  get cfgList() {
    return this.type ? CompanyDeliveryTB : CompanyJobTB
  }

  open(type, id) {
    this.show = true;
    this.businessid = id;
    this.type = type;
    this.onSearch();
    this.initOptions();
  }
}
</script>

<style scoped lang="scss">
@import "~assets/common.scss";
@import "~assets/scss/variables.scss";

#Company {
}
</style>
